package cn.com.dycc.sys_manage.rolesysmanagement.controller;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.sys_manage.rolesysmanagement.entity.Role;
import cn.com.dycc.sys_manage.rolesysmanagement.service.RoleMenuService;
import cn.com.dycc.util.JsonObjectResult;

/**
 * 
 * Description: 
 * Author: linfangan
 * Version: 1.0
 * Create Date Time: 2017年8月8日 下午9:37:26.
 * Update Date Time: 
 * @see
 */

@Controller
@RequestMapping("/rolemenu")
public class RoleMenuController extends BaseController{
	
	@Resource(name="roleMenuService")
	private RoleMenuService roleMenuService;
	
	//新增角色信息和管理角色权限
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addRoleMenu(Role role,String[] privIds,HttpServletRequest request){
		String opt_user_id = request.getSession().getAttribute("id").toString();
		String org_id = request.getSession().getAttribute("org_id").toString();
		role.setOpt_user_id(opt_user_id);
		role.setOrg_id(org_id);
		Map<String,Object> map = roleMenuService.addRoleMenu(role, privIds);
		return new JsonObjectResult(map);	
	}
	
	//更新角色信息和角色权限
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult revampRoleMenu(Role role,String[] privIds,HttpServletRequest request){
		String update_user_id = request.getSession().getAttribute("id").toString();
		String org_id = request.getSession().getAttribute("org_id").toString();
		role.setUpdate_user_id(update_user_id);
		role.setOrg_id(org_id);
		Map<String,Object> map = roleMenuService.revampRoleMenu(role, privIds);
		return new JsonObjectResult(map);
	}
	
	//查找角色信息和角色权限
	@RequestMapping("/findpart.do")
	//@ResponseBody
	public void findMenNoByRoleNo(String role_no,String sys_flag,HttpServletRequest request,HttpServletResponse respon) throws IOException{
		String org_id = request.getSession().getAttribute("org_id").toString();
		String map = roleMenuService.findMenNoByRoleNo(role_no,sys_flag,org_id);
		respon.setContentType("application/json;charset=UTF-8");
		respon.getWriter().println(map);
		//System.out.println(new JsonData(list).getData().toString());		
		//return new JsonData(list);
	}
}
